package com.yxw.yxnet_cd_center.customer_service.controller;

import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.customer_service.dto.PostDTO;
import com.yxw.yxnet_cd_center.customer_service.dto.PostQueryDTO;
import com.yxw.yxnet_cd_center.customer_service.service.IPostService;
import com.yxw.yxnet_cd_center.customer_service.vo.PostVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 岗位管理Controller控制层处理
 *
 * @author xiexuxin
 * @date 2023-09-17
 */

@Slf4j
@Api(value = "岗位管理", tags = "岗位管理")
@RestController
@Validated
@RequestMapping("/v1/post")
public class PostController {

    @Autowired
    private IPostService postService;

    /**
     * 新增岗位
     */
    @ApiOperation("添加岗位")
    @PostMapping("add-post")
    public BaseResult add(@RequestBody PostDTO postDTO) {
        log.info("开始处理【添加岗位】的请求，参数：{}", postDTO);
        postService.addPost(postDTO);
        return BaseResult.success();
    }

    /**
     * 删除岗位
     */
    @ApiOperation("根据id删除岗位")
    @PostMapping("/{postId}/deletePostById")
    public BaseResult remove(@PathVariable Long postId) {
        log.info("开始处理【根据id删除岗位】的请求，参数：{}", postId);
        postService.deletePostById(postId);
        return BaseResult.success();
    }

    /**
     * 批量删除岗位
     */
    @ApiOperation("根据id批量删除岗位")
    @PostMapping("/{postIds}/batch-delete")
    public BaseResult batchDelete(@PathVariable List<Long> postIds) {
        log.info("开始处理【根据id批量删除岗位】的请求，参数：{}", postIds);
        postService.deleteByPostIds(postIds);
        return BaseResult.success();
    }

    /**
     * 修改岗位
     */
    @ApiOperation("根据id修改岗位")
    @PostMapping("{postId}/update")
    public BaseResult edit(@PathVariable Long postId, @RequestBody PostDTO postDTO) {
        log.info("开始处理【根据id修改岗位】的请求，ID：{}，新数据：{}", postId, postDTO);
        postService.updatePost(postId, postDTO);
        return BaseResult.success();
    }

    /**
     * 根据id查询岗位信息
     */
    @ApiOperation(value = "根据id查询岗位信息")
    @GetMapping(value = "/{postId}")
    public BaseResult getInfo(@PathVariable("postId") Long postId) {
        log.info("开始处理【根据id查询岗位信息】的请求，ID：{}", postId);
        PostVO postVO = postService.selectPostById(postId);
        return BaseResult.success(postVO);
    }

    /**
     * 根据部门查询岗位
     */
    @ApiOperation(value = "根据部门查询岗位")
    @GetMapping(value = "/{deptId}/getPostByDept")
    public BaseResult getPostByDept(@PathVariable("deptId") Long deptId) {
        log.info("开始处理【根据id查询岗位信息】的请求，ID：{}", deptId);
        List<PostVO> postVO = postService.getPostByDept(deptId);
        return BaseResult.success(postVO);
    }

    /**
     * 查询岗位列表
     */
    @ApiOperation(value = "查询岗位列表")
    @PostMapping("/postList")
    public BaseResult postList() {
        log.info("开始处理【查询岗位列表】请求,无参数");
        List<PostVO> list = postService.postList();
        return BaseResult.success(list);
    }

    /**
     * 条件查询岗位列表
     */
    @ApiOperation(value = "条件查询岗位")
    @PostMapping(value = "/getPostList")
    public BaseResult<PageVO<PostVO>> getPostList(@RequestBody PostQueryDTO postQueryDTO) {
        log.info("开始处理【条件查询岗位】请求,参数:{}", postQueryDTO);
        PageVO<PostVO> pageVo = postService.getPostList(postQueryDTO);
        return ResultHelper.fillWithSuccess(pageVo);
    }
}
